//引入路由组件
import Home from '../pages/Home'
import Register from '../pages/Register'
import Login from '../pages/Login'
import Search from '../pages/Search'
import Detail from '../pages/Detail'
import AddCartSuccess from '../pages/AddCartSuccess'
import ShopCart from '../pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
import MyOrder from '@/pages/Center/MyOrder'
//路由配置信息
export default [
    {
        //加入购物车成功组件
        path: '/addcartsuccess',
        name:'addcartsuccess',
        component: AddCartSuccess,
        meta: { show: true }
    },
    {
        //购物车组件
        path: '/shopcart',
        component: ShopCart,
        meta: { show: true }
    },
    {
        //订单组件
        path: '/trade',
        component: Trade,
        meta: { show: true },
        //路由独享守卫
        beforeEnter:(to,from,next)=>{
            //去交易页面，必须是从购物车而来
            if(from.path == '/shopcart'){
                next()
            }else{
                //其它路由组件而来，停留在当前
                next(false)
            }
        }
    },
    {
        //支付组件
        path: '/pay',
        component: Pay,
        meta: { show: true },
        beforeEnter:(to,from,next)=>{
            if(from.path == '/trade'){
                next()
            }else{
                next(false)
            }
        }
    },
    {
        //支付成功组件
        path: '/paysuccess',
        component: PaySuccess,
        meta: { show: true }
    },
    {
        //用户中心
        path: '/center',
        component: Center,
        meta: { show: true },
        //二级路由组件
        children:[
            {
                path:'myorder',
                component: MyOrder,
            },
            {
                path:'/center',
                redirect:'/center/myorder'
            }
        ]
    },
    {
        path: '/home',
        component: Home,
        meta: { show: true }
    },
    {
        name: 'search',
        path: '/search/:keyword',
        component: Search,
        meta: { show: true }
    },
    {
        path: '/login',
        component: Login,
        meta: { show: false }
    },
    {
        path: '/register',
        component: Register,
        meta: { show: false }
    },
    {
        name: 'detail',  // 是当前路由的标识名称
        path: '/detail/:skuId',
        component: Detail,
    },
    //重定向，在项目跑起来的时候，访问/，立马让它定向到首页
    {
        path: '*',
        redirect: '/home'
    }
]